package demo.controller;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RefreshScope
public class NocasConfigController {
    @NacosInjected
    private NamingService namingService;

    @Value("${app.info}")
    private String info;

    @GetMapping("/info")
    public String getInfo() {
        return info;
    }

    @GetMapping("/getInstance/{service}")
    public List<Instance> getInstance(@PathVariable("service") String service) throws NacosException {
        return namingService.getAllInstances(service);
    }
}
